{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[3, 3],\n",
       "        [4, 3],\n",
       "        [1, 1]]),\n",
       " array([ 1,  1, -1]))"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "#必须要是线性可分的数据集\n",
    "def load_data():\n",
    "    data = np.array([[3, 3, 1], [4, 3, 1], [1, 1, -1]])\n",
    "    x = data[:, :2]\n",
    "    y = data[:, 2]\n",
    "    return x, y\n",
    "\n",
    "\n",
    "x, y = load_data()\n",
    "x, y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "N, M = x.shape\n",
    "w = np.ones(M)\n",
    "b = 0.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAf3klEQVR4nO3de3BV130v8O9PbxACgREGIwkhgY2xZTDIPML7Iekkt00mt8lMcm/apu0dxrnTtJ3c9rap58a30/SPNmkm08x9xONkrm/T28TTJI6bJhISSAgwBgsMGIwfEiAL8ZBACCH0ln73j6W99zlCso6kffY5S/p+ZjQRW+fss3Z28tXSWmuvn6gqiIjIXknxbgAREU0Pg5yIyHIMciIiyzHIiYgsxyAnIrJcSjw+dPHixVpQUBCPjyYistbp06dvq2rO6ONxCfKCggLU19fH46OJiKwlIk1jHefQChGR5RjkRESWY5ATEVmOQU5EZDkGOdEMozoMHbgI7X8bqgPx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L/kMgP+rxpsAskVkWTCtm5worsUKqnpDVc+MfH8fwCUAy0e9zIr7EuW1WGHkv+uukX+mjnyNXsFgy32J5lqsICK5AP4dgJfHeYmv9yQhgzwKywE0h/37Giz9P+KIrSN/Tv5aRJ6Kd2MmIiIFAJ6F6TGFs+6+fMy1AJbcl5E/4c8CaAVQparW3pcorgWw4758F8B/BTA8zs99vSe2BrmMcczK39wAzsDsn7AOwPcAvBbn9nwsEZkH4KcA/kRVO0f/eIy3JOx9meBarLkvqjqkquth6uZuEpGnR73EmvsSxbUk/H0Rkd8A0Kqqpz/uZWMcm/I9sTXIrwHIC/t3LoDrcWrLtKhqp/PnpKr+CkCqiCyOc7PGJCKpMMH3T6r6szFeYs19mehabLovDlXtAFALIDTqR9bcF8d412LJfdkG4NMjdYx/DGCviPxo1Gt8vSe2BvnrAH5nZOZ3C4B7qnoj3o2aChFZKiIy8v0mmHtyJ76tethIG38A4JKqfmecl1lxX6K5FovuS46IZI98PwfAfgDvjXqZLfdlwmux4b6o6tdVNVdN+csvADisql8a9TJf74lvNTv9JCL/DDM7vVhErgF4EWbiA6r6vwH8CmbWtwFAN4Dfi09LJxbFtXwOwFdEZBBAD4Av6Mi0doLZBuC3AbwzMoYJAH8JIB+w7r5Ecy223JdlAF4RkWSYUHtVVX8pIs8D1t2XaK7FlvvykFjeEz6iT0RkOVuHVoiIaASDnIjIcgxyIiLLMciJiCzHICcishyDnIjIcgxyIiLL/X8l3yjb045jRAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#把线画出来,线就是wx + b = 0\n",
    "def draw():\n",
    "    X = np.arange(x[:, 0].min(), x[:, 0].max(), 1)\n",
    "    Y = np.empty([len(X)])\n",
    "\n",
    "    for i in range(len(X)):\n",
    "        Y[i] = (-w[0] * X[i] - b) / w[1]\n",
    "    plt.plot(X, Y, c='red')\n",
    "\n",
    "    for i in range(len(X)):\n",
    "        Y[i] = (1 - w[0] * X[i] - b) / w[1]\n",
    "    plt.plot(X, Y, c='blue')\n",
    "\n",
    "    for i in range(len(X)):\n",
    "        Y[i] = (-1 - w[0] * X[i] - b) / w[1]\n",
    "    plt.plot(X, Y, c='green')\n",
    "\n",
    "    plt.scatter(x[:, 0], x[:, 1], c=y)\n",
    "\n",
    "    plt.show()\n",
    "\n",
    "\n",
    "draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle lam_{1} \\left(- B - 3 w_{1} - 3 w_{2} + 1\\right) + lam_{2} \\left(- B - 4 w_{1} - 3 w_{2} + 1\\right) + lam_{3} \\left(B + w_{1} + w_{2} + 1\\right) + \\frac{w_{1}^{2}}{2} + \\frac{w_{2}^{2}}{2}$"
      ],
      "text/plain": [
       "lam1*(-B - 3*w1 - 3*w2 + 1) + lam2*(-B - 4*w1 - 3*w2 + 1) + lam3*(B + w1 + w2 + 1) + w1**2/2 + w2**2/2"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sympy as sp\n",
    "\n",
    "#定义变量\n",
    "w1, w2, B, lam1, lam2, lam3 = sp.symbols('w1 w2 B lam1 lam2 lam3')\n",
    "\n",
    "#最小化函数\n",
    "f = (w1**2 + w2**2) / 2\n",
    "\n",
    "#约束条件\n",
    "st1 = 1 - (3 * w1 + 3 * w2 + B)  # <= 0\n",
    "st2 = 1 - (4 * w1 + 3 * w2 + B)  # <= 0\n",
    "st3 = 1 - (-1 * w1 + -1 * w2 + -B)  # <= 0\n",
    "\n",
    "#定义拉格朗日乘子式\n",
    "L = f + lam1 * st1 + lam2 * st2 + lam3 * st3\n",
    "\n",
    "L"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#定义kkt条件\n",
    "#lam * st = 0\n",
    "lam_st_kkts = [\n",
    "    lam1 * st1,  # == 0\n",
    "    lam2 * st2,  # == 0\n",
    "    lam3 * st3,  # == 0\n",
    "]\n",
    "\n",
    "#lam >= 0\n",
    "lam_kkts = [\n",
    "    sp.Ge(lam1, 0),  # >= 0\n",
    "    sp.Ge(lam2, 0),  # >= 0\n",
    "    sp.Ge(lam3, 0),  # >= 0\n",
    "]\n",
    "\n",
    "#st <= 0\n",
    "st_kkts = [\n",
    "    sp.Le(st1, 0),  # <= 0\n",
    "    sp.Le(st1, 0),  # <= 0\n",
    "    sp.Le(st1, 0),  # <= 0\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 0, -1, 0, 0, 0),\n",
       " (0, 0, B, 0, 0, 0),\n",
       " (0, 1, -2, 3/2, -1, 1/2),\n",
       " (6/13, 4/13, -23/13, 0, 2/13, 2/13),\n",
       " (1/2, 1/2, -2, 1/4, 0, 1/4)]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求导\n",
    "d_w1 = sp.diff(L, w1)\n",
    "d_w2 = sp.diff(L, w2)\n",
    "d_b = sp.diff(L, B)\n",
    "\n",
    "#解方程组\n",
    "solve = sp.solve([d_w1, d_w2, d_b, *lam_st_kkts], w1, w2, B, lam1, lam2, lam3)\n",
    "\n",
    "solve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'w1': 1/2, 'w2': 1/2, 'B': -2, 'lam1': 1/4, 'lam2': 0, 'lam3': 1/4}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#遍历结果,找能使f得到最小值的解\n",
    "min_solve = None\n",
    "min_subs = 1e20\n",
    "for i in solve:\n",
    "    i = {\n",
    "        'w1': i[0],\n",
    "        'w2': i[1],\n",
    "        'B': i[2],\n",
    "        'lam1': i[3],\n",
    "        'lam2': i[4],\n",
    "        'lam3': i[5]\n",
    "    }\n",
    "\n",
    "    #检查是否符合kkt条件,不符合的都不要\n",
    "    if not lam_kkts[0].subs(i):\n",
    "        continue\n",
    "    if not lam_kkts[1].subs(i):\n",
    "        continue\n",
    "    if not lam_kkts[2].subs(i):\n",
    "        continue\n",
    "\n",
    "    if st_kkts[0].subs(i) != True:\n",
    "        continue\n",
    "    if st_kkts[1].subs(i) != True:\n",
    "        continue\n",
    "    if st_kkts[2].subs(i) != True:\n",
    "        continue\n",
    "\n",
    "    #找能使f得到最小值的解\n",
    "    subs = f.subs(i)\n",
    "    if min_subs > subs:\n",
    "        min_subs = subs\n",
    "        min_solve = i\n",
    "\n",
    "min_solve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deXSV933n8fdPQgixYxA7QuxIxtjGGLMYs29iE1zlNE1TT9OmNO0ZJ2mbk06S6TjNnJwm06nTaacn05wkU2fSJCfRwyo2gw0YG4PZbaPLbvZN7KBdur/54yfpEoJAoHv13Ef38zqHg/Toufd+Hz/4w8Pv+f2+j7HWIiIiwZXidwEiItI8CnIRkYBTkIuIBJyCXEQk4BTkIiIB18aPD+3Ro4fNzs7246NFRAJr7969V621mfdv9yXIs7Oz2bNnjx8fLSISWMaY0w/arqEVEZGAU5CLiAScglxEJOAU5CIiAacgFxEJuJjMWjHGnALuALVAjbV2bCzeV0REHi2W0w+nWWuvxvD9RESkCQI1tLJuHfzgB3D6gTMpRUSSU6yC3AJvGWP2Gm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Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "w[0] = min_solve['w1']\n",
    "w[1] = min_solve['w2']\n",
    "b = min_solve['B']\n",
    "\n",
    "draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
